/**
 * 控制监控js
 */
function $(str) {
	return document.getElementById(str);
}
var canvasInfo = {
	width:window.innerWidth,
	height:window.innerHeight,
	ctx:$("desk").getContext("2d")
}
function log(s){
	console.log(s);
}



var tank = [];


(function() {
	var Control1 = new Control("Control1");
	
	addEventListener("keydown", keyDownHander, true);

	addEventListener("keyup", keyUpHander, true);
	// keyDown一直触发，只要按下去后
	function keyDownHander(e) {
		var key = e.keyCode;
		
		Control1.movement.moveAble=true; 
		log("keyDownHander"+key);
		
		switch(key){
			 case 87:
			 	Control1.setDirection(Control.DIR_UP);
		    	 break
		  	 case 68:
			 	Control1.setDirection(Control.DIR_RIGHT);
		    	 break
			 case 83:
			 	Control1.setDirection(Control.DIR_DOWN);
		    	 break
		  	 case 65 :
			 	Control1.setDirection(Control.DIR_LEFT);
		    	 break
		  	 default:
		}
		
	}
	function keyUpHander(e) {
		var key = e.keyCode;
		log("keyUpHander"+key);
		Control1.movement.moveAble=false; 
	}

	
	tank.push(new Tank(Control1));
})();


function drawing() {

	canvasInfo.ctx.clearRect(0, 0, canvasInfo.width, canvasInfo.height);

	var len = tank.length;

	for (var i = 0; i < len; i++) {

		tank[i].drawSelf();

	}
	setTimeout(drawing, 50);
}

drawing();
